const views = require('koa-views');
const serve = require('koa-static');

class Web {
    constructor(app) {
        // const path = require('path')
        // app.use(views(path.join(__dirname, '/'), {extension:'html'}))
        // app.use(views(__dirname, {extension: 'html'}))
        // app.use(views(__dirname), {
        //     extension: 'ejs', // 使用 EJS 模板引擎
        // })
        app.use(views(__dirname))
        // 配置静态文件目录
        app.use(serve(__dirname));
    }

    async index(ctx) {
        // await ctx.render('client.js')
        // await ctx.render('index_.html', {externalJs: './client.js'}) // 必须安装 koa-views
        await ctx.render('index_.html', {JS: './client.js'})
    }
}

module.exports = {
    Web,
}
